﻿using OnlineAuction.Business;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OnlineAuction
{
    public partial class ChangePassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Cookies["UserInfo"] == null)
            {
                Response.Redirect("Home.aspx");
            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            UserBO bo = new UserBO();
            if (bo.CheckUserPassword(Request.Cookies["UserInfo"]["UserName"].ToString(), txtOldPassword.Text))
            {
                if (txtNewPassword.Text.CompareTo(txtConfirmNewPassword.Text) == 0)
                {
                    if (bo.ChangePassword(Request.Cookies["UserInfo"]["UserName"].ToString(), txtNewPassword.Text))
                    {
                        ScriptManager.RegisterStartupScript(this, GetType(), "alertmsg",
                        "alert('Completed...!!!');", true);
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this, GetType(), "alertmsg",
                            "alert('Error...!!!');", true);
                    }
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, GetType(), "alertmsg",
                    "alert('two new password not same...!!!');", true);
                }
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "alertmsg",
                    "alert('The old password not correct...!!!');", true);
            }
        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            txtOldPassword.Text = "";
            txtNewPassword.Text = "";
            txtConfirmNewPassword.Text = "";
        }
    }
}